<script setup lang="ts">
import { reactive, ref } from 'vue';
import { useMenuList } from "@/api/common";


const page = ref(1);
const pageSize = ref(10);
const keyword = ref("1");
const userInfo = reactive({
  name: "test",
});

const params = reactive({
  page: page,
  pageSize: 10,
  keyword: "1",
  userInfo: {
    name: "test",
  },
});

const addPage = () => {
  page.value = page.value + 1;
}

const [{ loading, data, error }, { abortController, execute }] = useMenuList({
  enabled: true,
  watchKeys: ["page", "pageSize", "userInfo"],
  query: {
    page: page,
    pageSize: pageSize,
    keyword: keyword,
    userInfo: userInfo,
  },
  onSuccess: (data) => {
    console.log(data);
    return data.list[page.value];
  },
});

</script>

<template>
  <header>
    <img alt="Vue logo" class="logo" src="./assets/logo.svg" width="125" height="125" />

    <div class="wrapper">
    </div>
  </header>

  <main>
    <p> loading: {{ loading }}</p>
    <p>第{{ page }}页数据：{{ JSON.stringify(data) }}</p>

    <button @click="addPage">下一页</button>

  </main>
</template>

<style scoped>
header {
  line-height: 1.5;
}

.logo {
  display: block;
  margin: 0 auto 2rem;
}

@media (min-width: 1024px) {
  header {
    display: flex;
    place-items: center;
    padding-right: calc(var(--section-gap) / 2);
  }

  .logo {
    margin: 0 2rem 0 0;
  }

  header .wrapper {
    display: flex;
    place-items: flex-start;
    flex-wrap: wrap;
  }
}
</style>
